package com.projles.release1;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.LinearLayout;

public class InicialActivity extends Activity {
	
	private CountDownTimer countdown;
	private final long TEMPO_LIMITE_PARA_RESPONDER = 7000; //em milisegundos
	private int tick = 0;
	
	private LinearLayout mainLayout;
	private MediaPlayer player;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.inicial);
        
        player = MediaPlayer.create(this, R.raw.musica_inicial);
		player.setLooping(false);
        player.start();
        
        mainLayout = (LinearLayout) findViewById(R.id.layout_inicial);
        
        countdown = new CountDownTimer(TEMPO_LIMITE_PARA_RESPONDER, 500) {
			
			@Override
			public void onTick(long tempoRestante) {
				if (tick == 2) {
					mainLayout.setBackgroundResource(R.drawable.um);
				}
				if (tick == 3) {
					mainLayout.setBackgroundResource(R.drawable.dois);
				}
				if (tick == 4) {
					mainLayout.setBackgroundResource(R.drawable.tres);
				}
				if (tick == 5) {
					mainLayout.setBackgroundResource(R.drawable.quatro);
				}
				if (tick == 6) {
					mainLayout.setBackgroundResource(R.drawable.cinco);
				}
				if (tick == 7) {
					mainLayout.setBackgroundResource(R.drawable.seis);
				}
				if (tick == 8) {
					mainLayout.setBackgroundResource(R.drawable.sete);
				}
				tick++;
			}
			
			@Override
			public void onFinish() {
				Intent i = new Intent(InicialActivity.this, LoginActivity.class);
	    		startActivity(i);
	    		finish();
	    	}
		};
		
		countdown.start();
    }

	
	@Override
	protected void onStop() {
		super.onStop();
		countdown.cancel();
		finish();
	}
    
    
    
    
}
    